# Import Qt libraries
from PySide6.QtWidgets import *
from PySide6.QtCore import QFile
# Import UI developed in Qt Creator
from Ui_btn import Ui_MainWindow  # 导入界面
# Import PseudoSensor
# Import system tools and datetime
import sys
import statistics
import time
import datetime
# Create and start the Qt application
class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        
        # 设置界面为用户设计的界面
        self.ui = Ui_MainWindow() 
        self.ui.setupUi(self) 
        self.ui.pushButton.clicked.connect(self.pushButton1_func) # 按键1绑定clicked信号

        self.ui.pushButton_2.pressed.connect(self.pushButton2_func) # 按键2绑定pressed信号

        self.ui.pushButton_3.released.connect(self.pushButton3_func) # 按键3绑定released信号

        self.ui.pushButton_4.toggled.connect(self.pushButton4_func) # 按键4绑定toggled信号
        self.ui.pushButton_4.setCheckable(True)                     # 设置按键4的checkabel属性为使能

        self.ui.pushButton_5.clicked.connect(self.pushButton5_func) # 按键5绑定clicked信号
        self.ui.pushButton_5.setAutoRepeat(True)                    # 按键5设置长按触发
        
        self.ui.pushButton_6.clicked.connect(self.pushButton6_func) # 按键6绑定clicked信号
        self.ui.pushButton_6.setAutoRepeat(True)                    # 按键6设置长按触发
        self.ui.pushButton_6.setAutoRepeatInterval(2000)            # 触发间隔设置为2s
        
    def pushButton1_func(self):
        print("按键1按下")

    def pushButton2_func(self):
        print("按键2按下")

    def pushButton3_func(self):
        print("按键3按下")

    def pushButton4_func(self,check):
        print("按键4按下 %d " % check)    

    def pushButton5_func(self):
        print("按键5按下")

    def pushButton6_func(self):
        print("按键6按下")
        print(datetime.datetime.now()) # 打印出触发间隔时间
        
    def closeAndExit(self):
        sys.exit()

if __name__ == "__main__":
    app = QApplication(sys.argv) # 初始化QApplication

    # 初始化界面并显示界面
    window = MainWindow() 
    window.setFixedSize(window.width(), window.height())
    window.show() 

    sys.exit(app.exec())
